
def pout = new PrintWriter(new BufferedWriter(new FileWriter("geneidmapping.txt")))
def dir = new File("geneid")
dir.eachFile { f ->
  f.splitEachLine("\t") { line ->
    def geneid = line[1]
    def extid = line[5]
    extid.split("\\|").each { eid ->
      if ((eid.indexOf("MGI")>-1) || 
	  (eid.indexOf("SGD")>-1) || 
	  (eid.indexOf("WBGene")>-1) || 
	  (eid.indexOf("ZDB")>-1) || 
	  (eid.indexOf("FBgn")>-1)) {
	if (eid.indexOf(":")>-1 && eid.indexOf("MGI:") == -1 ) {
	  eid = eid.substring(eid.indexOf(":")+1)
	}
	pout.println("$geneid\t$eid")
      }
    }
  }
}

pout.flush()
pout.close()
